package com.lovo.csc.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lovo.csc.bean.AdminBean;
import com.lovo.csc.bean.UserBean;
import com.lovo.csc.bean.UserInfoBean;
import com.lovo.csc.service.IUserInfoService;
import com.lovo.csc.service.IUserService;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    RabbitTemplate rabbitTemplate;
    @Autowired
    IUserService service;

    @Autowired
    IUserInfoService userInfoService;


    @RequestMapping("findByStatus")
    public Page<UserBean> findByStatus(Integer status, Integer pageNO) {
        return service.findByStatus(status, pageNO);
    }

    @RequestMapping("findById")
    public UserBean findById(long userId) {
        return service.findById(userId);
    }

    @RequestMapping("audit")
    public String audit(long userId, Integer auditState, String str, String adminName) {
        service.updateUserinfo(userId, auditState,str,adminName);
        return "ok";
    }

    @RequestMapping("showUserInfo")
    public UserBean showUserInfo(long userId) {

        UserBean userBean = service.findUserById(userId);

        return userBean;
    }

    @RequestMapping("findByUserFreezeStatus")
    public Page<UserBean> findByUserFreezeStatus(Integer pageNO) {
        return service.findByUserFreezeStatus(pageNO);
    }

    @RequestMapping("updateFreezeStatus")
    public String updateFreezeStatusFailed(long userId, Integer status) {
        service.updateUserFreezeStatus(userId, status);
        return "ok";
    }

    @GetMapping("updateMoneyByUserName/{userName}/{money}")
    public String updateMoneyByUserName(@PathVariable("userName") String userName, @PathVariable("money") float money) {
        service.updateMoneyByUserName(userName, money);
        return "ok";
    }

    @GetMapping("getDiscount/{userName}")
    public float getDiscount(@PathVariable("userName") String userName){
        return service.getDiscount(userName);
    }
}
